package com.todoapp.web.servlet;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

import org.apache.log4j.Logger;

import todo.core.testdb.DerbyManager;


public class ContextListener implements ServletContextListener {
	private static Logger log = Logger.getLogger(ContextListener.class);

	/*
	 * (non-Javadoc)
	 * @see javax.servlet.ServletContextListener#contextInitialized(javax.servlet.ServletContextEvent)
	 */
	public void contextInitialized(ServletContextEvent arg0) {
		
		try {
			DerbyManager.createDatabase();
		} catch (Exception e) {
			log.info("error during DerbyManager.createDatabase()", e);
		}

	}

	/*
	 * (non-Javadoc)
	 * @see javax.servlet.ServletContextListener#contextDestroyed(javax.servlet.ServletContextEvent)
	 */
	public void contextDestroyed(ServletContextEvent arg0) {
		try {
			DerbyManager.cleanupDatabase();
		} catch (Exception e) {
			log.info("error during DerbyManager.cleanupDatabase()", e);
		}

	}

}
